<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script src="/resources/manage/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/resources/ace/css/cacheCloud-appCommand.css"/>
<div class="header navbar navbar-inverse navbar-fixed-top">
	<div class="header-inner">
		<a class="navbar-brand" href="/manage/total/list">
			<img src="/resources/manage/img/logo_new.png" alt="logo" class="img-responsive" />
		</a>
		
		<a href="javascript:;" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
			<img src="/resources/manage/img/menu-toggler.png" alt="" />
		</a>
		
		<ul class="nav navbar-nav pull-right">
			<li class="dropdown user">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
					<span class="glyphicon glyphicon-cog"></span>
				<span class="username">${userInfo.chName}</span>
				<i class="fa fa-angle-down"></i>
				</a>
				<ul class="dropdown-menu">
					<li><a target="_self" href="/admin/app/list"><span class="glyphicon glyphicon-home"></span> 应用前台</a></li>
					<li><a href="javascript;" data-target="#addUserModal${userInfo.id}" data-toggle="modal"><span class="glyphicon glyphicon-pencil"></span> 修改资料</a></li>
					<c:if test="${userInfo.name ne 'admin'}">
						<li><a id="updatePwdBtn" href="javascript;"><span class="glyphicon glyphicon-lock"></span> 修改密码</a></li>
					</c:if>
					<li><a href="/manage/logout"><span class="glyphicon glyphicon-log-out"></span> 注销</a></li>
				</ul>
			</li>
		</ul>
	</div>
	<div class="editDialog" id="updatePwdDialog" style="z-index: 10">
		<div class="editDialog-con">
			<div class="editDialog-con-title">
				<span>修改密码</span>
			</div>
			<div class="editDialog-con-form">
				<div class="form-item" id="dialogInput">
					<p>密码:</p>
					<input type="password" class="cacheCloud-input">
					<p class="help-block">密码中必须包含字母、数字，至少8个字符</p>
				</div>
			</div>
			<div class="editDialog-con-btns">
				<div></div>
				<div>
					<button class="btn btn-default" id="closeDialog">取消</button>
					<button class="btn btn-info" id="saveDialog" data-id="${userInfo.id}">保存</button>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="clearfix"></div>

<c:set var="user" value="${userInfo}"/>
<%@include file="../user/addUser.jsp" %>
<script>
   	$(function() {
        var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{8,30}');
        $("#updatePwdBtn").click(function(e) {
            e.preventDefault();
            $("#updatePwdDialog").css("display", "flex");
        })
        $("#closeDialog").click(function() {
            $("#updatePwdDialog").css("display", "none");
        });
        $("#saveDialog").click(function() {
			var pwd = $("#dialogInput input").val();
			if(!pwd) {
				alert("请填写密码");
				return;
			}
			if(!pwdRegex.test(pwd)) {
                alert("您的密码复杂度太低，密码中必须包含字母、数字、特殊字符至少8个字符，请修改密码！");
				return;
			}
			$.ajax({
                url: "/user/updatePwd",
				type: "post",
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				data: {
					userId: $(this).data("id"),
					password: pwd
				},
				success: function(res) {
					if(res.status) {
                        alert("修改成功");
                        $("#dialogInput input").val("");
                        $("#updatePwdDialog").css("display", "none");
                    }
					else alert("修改失败");
				}
			});
        });
    })
</script>
